"use strict";

/*
 * MikoPBX - free phone system for small business
 * Copyright © 2017-2023 Alexey Portnov and Nikolay Beketov
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program.
 * If not, see <https://www.gnu.org/licenses/>.
 */

/* global globalRootUrl, globalTranslate, Extensions,Form, SoundFilesSelector */

/**
 * callQueue module.
 * @module callQueue
 */
var callQueue = {
  // Default extension number
  defaultExtension: '',
  // The input field for the extension number
  $extension: $('#extension'),
  // List of available members for this call queue
  AvailableMembersList: [],

  /**
   * jQuery object for the form.
   * @type {jQuery}
   */
  $formObj: $('#queue-form'),
  // The accordion UI components in the form
  $accordions: $('#queue-form .ui.accordion'),
  // The dropdown UI components in the form
  $dropDowns: $('#queue-form .dropdown'),
  // The field for form error messages
  $errorMessages: $('#form-error-messages'),
  // The checkbox UI components in the form
  $checkBoxes: $('#queue-form .checkbox'),
  // The select for forwarding in the form
  forwardingSelect: '#queue-form .forwarding-select',
  // The button to delete a row
  $deleteRowButton: $('.delete-row-button'),
  // The dropdown for periodic announce sound selection
  $periodicAnnounceDropdown: $('#queue-form .periodic-announce-sound-id-select'),
  // The row of the member
  memberRow: '#queue-form .member-row',
  // The dropdown for extension selection
  $extensionSelectDropdown: $('#extensionselect'),
  // The table of extensions
  $extensionsTable: $('#extensionsTable'),

  /**
   * Validation rules for the form fields before submission.
   *
   * @type {object}
   */
  validateRules: {
    name: {
      identifier: 'name',
      rules: [{
        type: 'empty',
        prompt: globalTranslate.cq_ValidateNameEmpty
      }]
    },
    extension: {
      identifier: 'extension',
      rules: [{
        type: 'number',
        prompt: globalTranslate.cq_ValidateExtensionNumber
      }, {
        type: 'empty',
        prompt: globalTranslate.cq_ValidateExtensionEmpty
      }, {
        type: 'existRule[extension-error]',
        prompt: globalTranslate.cq_ValidateExtensionDouble
      }]
    }
  },

  /**
   * Initialize the call queue form
   */
  initialize: function initialize() {
    // Get phone extensions and set available queue members
    Extensions.getPhoneExtensions(callQueue.setAvailableQueueMembers); // Initialize UI components

    callQueue.$accordions.accordion();
    callQueue.$dropDowns.dropdown();
    callQueue.$checkBoxes.checkbox(); // Set up periodic announce dropdown behaviour

    callQueue.$periodicAnnounceDropdown.dropdown({
      onChange: function onChange(value) {
        if (parseInt(value, 10) === -1) {
          callQueue.$periodicAnnounceDropdown.dropdown('clear');
        }
      }
    }); // Initialize forwarding select

    $(callQueue.forwardingSelect).dropdown(Extensions.getDropdownSettingsWithEmpty()); // Set up dynamic availability check for extension number

    callQueue.$extension.on('change', function () {
      var newNumber = callQueue.$formObj.form('get value', 'extension');
      Extensions.checkAvailability(callQueue.defaultNumber, newNumber);
    }); // Initialize drag and drop for extension table rows

    callQueue.initializeDragAndDropExtensionTableRows(); // Set up row deletion from queue members table

    callQueue.$deleteRowButton.on('click', function (e) {
      e.preventDefault();
      $(e.target).closest('tr').remove();
      callQueue.reinitializeExtensionSelect();
      callQueue.updateExtensionTableView();
      Form.dataChanged();
      return false;
    }); // Initialize audio message select

    $('#queue-form .audio-message-select').dropdown(SoundFilesSelector.getDropdownSettingsWithEmpty()); // Initialize the form

    callQueue.initializeForm(); // Set the default extension number

    callQueue.defaultExtension = callQueue.$formObj.form('get value', 'extension');
  },

  /**
   * Set available members for the call queue
   * @param {Object} arrResult - The list of available members
   */
  setAvailableQueueMembers: function setAvailableQueueMembers(arrResult) {
    // Loop through the result and populate AvailableMembersList
    $.each(arrResult.results, function (index, extension) {
      callQueue.AvailableMembersList.push({
        number: extension.value,
        callerid: extension.name
      });
    }); // Reinitialize the extension select and update the view

    callQueue.reinitializeExtensionSelect();
    callQueue.updateExtensionTableView();
  },

  /**
   * Return the list of available members for the queue
   * @returns {Array} - The list of available members
   */
  getAvailableQueueMembers: function getAvailableQueueMembers() {
    var result = []; // Loop through available members and add to result if not already selected

    callQueue.AvailableMembersList.forEach(function (member) {
      if ($(".member-row#".concat(member.number)).length === 0) {
        result.push({
          name: member.callerid,
          value: member.number
        });
      }
    }); // result.sort((a, b) => ((a.name > b.name) ? 1 : ((b.name > a.name) ? -1 : 0)));

    return result;
  },

  /**
   * Reinitialize extension select with consideration for already selected members
   */
  reinitializeExtensionSelect: function reinitializeExtensionSelect() {
    // Setup dropdown with available queue members
    callQueue.$extensionSelectDropdown.dropdown({
      action: 'hide',
      forceSelection: false,
      onChange: function onChange(value, text) {
        // If a value is selected
        if (value) {
          // Get the last template row, clone it and populate with the selected member data
          var $tr = $('.member-row-tpl').last();
          var $clone = $tr.clone(true);
          $clone.removeClass('member-row-tpl').addClass('member-row').show();
          $clone.attr('id', value);
          $clone.find('.number').html(value);
          $clone.find('.callerid').html(text); // Insert the new member row into the table

          if ($(callQueue.memberRow).last().length === 0) {
            $tr.after($clone);
          } else {
            $(callQueue.memberRow).last().after($clone);
          } // Reinitialize the extension select and update the view


          callQueue.reinitializeExtensionSelect();
          callQueue.updateExtensionTableView();
          Form.dataChanged();
        }
      },
      // Set the values for the dropdown
      values: callQueue.getAvailableQueueMembers()
    });
  },

  /**
   * Initialize Drag and Drop functionality for the extension table rows
   */
  initializeDragAndDropExtensionTableRows: function initializeDragAndDropExtensionTableRows() {
    callQueue.$extensionsTable.tableDnD({
      onDragClass: 'hoveringRow',
      // CSS class to be applied while a row is being dragged
      dragHandle: '.dragHandle',
      // Class of the handler to initiate the drag action
      onDrop: function onDrop() {
        // Callback to be executed after a row has been dropped
        // Trigger change event to acknowledge the modification
        Form.dataChanged();
      }
    });
  },

  /**
   * Display a placeholder if the table has zero rows
   */
  updateExtensionTableView: function updateExtensionTableView() {
    // Placeholder to be displayed
    var dummy = "<tr class=\"dummy\"><td colspan=\"4\" class=\"center aligned\">".concat(globalTranslate.cq_AddQueueMembers, "</td></tr>");

    if ($(callQueue.memberRow).length === 0) {
      $('#extensionsTable tbody').append(dummy); // Add the placeholder if there are no rows
    } else {
      $('#extensionsTable tbody .dummy').remove(); // Remove the placeholder if rows are present
    }
  },

  /**
   * Callback function to be called before the form is sent
   * @param {Object} settings - The current settings of the form
   * @returns {Object} - The updated settings of the form
   */
  cbBeforeSendForm: function cbBeforeSendForm(settings) {
    var result = settings; // Retrieve form values

    result.data = callQueue.$formObj.form('get values');
    var arrMembers = []; // Iterate through each member row and add to arrMembers

    $(callQueue.memberRow).each(function (index, obj) {
      if ($(obj).attr('id')) {
        arrMembers.push({
          number: $(obj).attr('id'),
          priority: index
        });
      }
    }); // Validate if any members exist

    if (arrMembers.length === 0) {
      result = false;
      callQueue.$errorMessages.html(globalTranslate.cq_ValidateNoExtensions);
      callQueue.$formObj.addClass('error');
    } else {
      result.data.members = JSON.stringify(arrMembers);
    }

    return result;
  },

  /**
   * Callback function to be called after the form has been sent.
   * @param {Object} response - The response from the server after the form is sent
   */
  cbAfterSendForm: function cbAfterSendForm(response) {
    callQueue.defaultNumber = callQueue.$formObj.form('get value', 'extension');
  },

  /**
   * Initialize the form with custom settings
   */
  initializeForm: function initializeForm() {
    Form.$formObj = callQueue.$formObj;
    Form.url = "".concat(globalRootUrl, "call-queues/save"); // Form submission URL

    Form.validateRules = callQueue.validateRules; // Form validation rules

    Form.cbBeforeSendForm = callQueue.cbBeforeSendForm; // Callback before form is sent

    Form.cbAfterSendForm = callQueue.cbAfterSendForm; // Callback after form is sent

    Form.initialize();
  }
};
/**
 * Checks if the number is taken by another account
 * @returns {boolean} True if the parameter has the 'hidden' class, false otherwise
 */

$.fn.form.settings.rules.existRule = function (value, parameter) {
  return $("#".concat(parameter)).hasClass('hidden');
};
/**
 *  Initialize Call Queues modify form on document ready
 */


$(document).ready(function () {
  callQueue.initialize();
});
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9DYW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iB7XG4gICAgICAgICAgICBpZGVudGlmaWVyOiAnbmFtZScsXG4gICAgICAgICAgICBydWxlczogW1xuICAgICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogJ2VtcHR5JyxcbiAgICAgICAgICAgICAgICAgICAgcHJvbXB0OiBnbG9iYWxUcmFuc2xhdGUuY3FfVmFsaWRhdGVOYW1lRW1wdHksXG4gICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIF0sXG4gICAgICAgIH0sXG4gICAgICAgIGV4dGVuc2lvbjoge1xuICAgICAgICAgICAgaWRlbnRpZmllcjogJ2V4dGVuc2lvbicsXG4gICAgICAgICAgICBydWxlczogW1xuICAgICAgICAgICAgICAgIHtcbiAgICAgICAgICAgICAgICAgICAgdHlwZTogJ251bWJlcicsXG4gICAgICAgICAgICAgICAgICAgIHByb21wdDogZ2xvYmFsVHJhbnNsYXRlLmNxX1ZhbGlkYXRlRXh0ZW5zaW9uTnVtYmVyLFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiAnZW1wdHknLFxuICAgICAgICAgICAgICAgICAgICBwcm9tcHQ6IGdsb2JhbFRyYW5zbGF0ZS5jcV9WYWxpZGF0ZUV4dGVuc2lvbkVtcHR5LFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgICAge1xuICAgICAgICAgICAgICAgICAgICB0eXBlOiAnZXhpc3RSdWxlW2V4dGVuc2lvbi1lcnJvcl0nLFxuICAgICAgICAgICAgICAgICAgICBwcm9tcHQ6IGdsb2JhbFRyYW5zbGF0ZS5jcV9WYWxpZGF0ZUV4dGVuc2lvbkRvdWJsZSxcbiAgICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgXSxcbiAgICAgICAgfSxcbiAgICB9LFxuXG4gICAgLyoqXG4gICAgICogSW5pdGlhbGl6ZSB0aGUgY2FsbCBxdWV1ZSBmb3JtXG4gICAgICovXG4g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dGhlIHZpZXdcbiAgICAgICAgY2FsbFF1ZXVlLnJlaW5pdGlhbGl6ZUV4dGVuc2lvblNlbGVjdCgpO1xuICAgICAgICBjYWxsUXVldWUudXBkYXRlRXh0ZW5zaW9uVGFibGVWaWV3KCk7XG4gICAgfSxcblxuICAgIC8qKlxuICAgICAqIFJldHVybiB0aGUgbGlzdCBvZiBhdmFpbGFibGUgbWVtYmVycyBmb3IgdGhlIHF1ZXVlXG4gICAgICogQHJldHVybnMge0FycmF5fSAtIFRoZSBsaXN0IG9mIGF2YWlsYWJsZSBtZW1iZXJzXG4gICAgICovXG4gICAgZ2V0QXZhaWxhYmxlUXVldWVNZW1iZXJzKCkge1xuICAgICAgICBjb25zdCByZXN1bHQgPSBbXTtcblxuICAgICAgICAvLyBMb29wIHRocm91Z2ggYXZhaWxhYmxlIG1lbWJlcnMgYW5kIGFkZCB0byByZXN1bHQgaWYgbm90IGFscmVhZHkgc2VsZWN0ZWRcbiAgICAgICAgY2FsbFF1ZXVlLkF2YWlsYWJsZU1lbWJlcnNMaXN0LmZvckVhY2goKG1lbWJlcikgPT4ge1xuICAgICAgICAgICAgaWYgKCQoYC5tZW1iZXItcm93IyR7bWVtYmVyLm51bWJlcn1gKS5sZW5ndGggPT09IDApIHtcbiAgICAgICAgICAgICAgICByZXN1bHQucHVzaCh7XG4gICAgICAgICAgICAgICAgICAgIG5hbWU6IG1lbWJlci5jYWxsZXJpZCxcbiAgICAgICAgICAgICAgICAgICAgdmFsdWU6IG1lbWJlci5udW1iZXIsXG4gICAgICAgICAgICAgICAgfSk7XG4gICAgICAgICAgICB9XG4gICAgICAgIH0pO1xuICAgICAgICAvLyByZXN1bHQuc29ydCgoYSwgYikgPT4gKChhLm5hbWUgPiBiLm5hbWUpID8gMSA6ICgoYi5uYW1lID4gYS5uYW1lKSA/IC0xIDogMCkpKTtcbiAgICAgICAgcmV0dXJuIHJlc3VsdDtcbiAgICB9LFxuXG4gICAgLyoqXG4gICAgICogUmVpbml0aWFsaXplIGV4dGVuc2lvbiBzZWxlY3Qgd2l0aCBjb25zaWRlcmF0aW9uIGZvciBhbHJlYWR5IHNlbGVjdGVkIG1lbWJlcnNcbiAgICAgKi9cbiAgICByZWluaXRpYWxpemVFeHRlbnNpb25TZWxlY3QoKSB7XG4gICAgICAgIC8vIFNldHVwIGRyb3Bkb3duIHdpdGggYXZhaWxhYmxlIHF1ZXVlIG1lbWJlcnNcbiAgICAgICAgY2FsbFF1ZXVlLiRleHRlbnNpb25TZWxlY3REcm9wZG93bi5kcm9wZG93bih7XG4gICAgICAgICAgICBhY3Rpb246ICdoaWRlJyxcbiAgICAgICAgICAgIGZvcmNlU2VsZWN0aW9uOiBmYWxzZSxcbiAgICAgICAgICAgIG9uQ2hhbmdlKHZhbHVlLCB0ZXh0KSB7XG4gICAgICAgICAgICAgICAgLy8gSWYgYSB2YWx1ZSBpcyBzZWxlY3RlZFxuICAgICAgICAgICAgICAgIGlmICh2YWx1ZSkge1xuICAgICAgICAgICAgICAgICAgICAvLyBHZXQgdGhlIGxhc3QgdGVtcGxhdGUgcm93LCBjbG9uZSBpdCBhbmQgcG9wdWxhdGUgd2l0aCB0aGUgc2VsZWN0ZWQgbWVtYmVyIGRhdGFcbiAgICAgICAgICAgICAgICAgICAgY29uc3QgJHRyID0gJCgnLm1lbWJlci1yb3ctdHBsJykubGFzdCgpO1xuICAgICAgICAgICAgICAgICAgICBjb25zdCAkY2xvbmUgPSAkdHIuY2xvbmUodHJ1ZSk7XG4gICAgICAgICAgICAgICAgICAgICRjbG9uZVxuICAgICAgICAgICAgICAgICAgICAgICAgLnJlbW92ZUNsYXNzKCdtZW1iZXItcm93LXRwbCcpXG4gICAgICAgICAgICAgICAgICAgICAgICAuYWRkQ2xhc3MoJ21lbWJlci1yb3cnKVxuICAgICAgICAgICAgICAgICAgICAgICAgLnNob3coKTtcbiAgICAgICAgICAgICAgICAgICAgJGNsb25lLmF0dHIoJ2lkJywgdmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICAkY2xvbmUuZmluZCgnLm51bWJlcicpLmh0bWwodmFsdWUpO1xuICAgICAgICAgICAgICAgICAgICAkY2xvbmUuZmluZCgnLmNhbGxlcmlkJykuaHRtbCh0ZXh0KTtcblxuICAgICAgICAgICAgICAgICAgICAvLyBJbnNlcnQgdGhlIG5ldyBtZW1iZXIgcm93IGludG8gdGhlIHRhYmxlXG4gICAgICAgICAgICAgICAgICAgIGlmICgkKGNhbGxRdWV1ZS5tZW1iZXJSb3cpLmxhc3QoKS5sZW5ndGggPT09IDApIHtcbiAgICAgICAgICAgICAgICAgICAgICAgICR0ci5hZnRlcigkY2xvbmUpO1xuICAgICAgICAgICAgICAgICAgICB9IGVsc2Uge1xuICAgICAgICAgICAgICAgICAgICAgICAgJChjYWxsUXVldWUubWVtYmVyUm93KS5sYXN0KCkuYWZ0ZXIoJGNsb25lKTtcbiAgICAgICAgICAgICAgICAgICAgfVxuXG4gICAgICAgICAgICAgICAgICAgIC8vIFJlaW5pdGlhbGl6ZSB0aGUgZXh0ZW5zaW9uIHNlbGVjdCBhbmQgdXBkYXRlIHRoZSB2aWV3XG4gICAgICAgICAgICAgICAgICAgIGNhbGxRdWV1ZS5yZWluaXRpYWxpemVFeHRlbnNpb25TZWxlY3QoKTtcbiAgICAgICAgICAgICAgICAgICAgY2FsbFF1ZXVlLnVwZGF0ZUV4dGVuc2lvblRhYmxlVmlldygpO1xuXG4gICAgICAgICAgICAgICAgICAgIEZvcm0uZGF0YUNoYW5nZWQoKTtcbiAgICAgICAgICAgICAgICB9XG4gICAgICAgICAgICB9LFxuICAgICAgICAgICAgLy8gU2V0IHRoZSB2YWx1ZXMgZm9yIHRoZSBkcm9wZG93blxuICAgICAgICAgICAgdmFsdWVzOiBjYWxsUXVldWUuZ2V0QXZhaWxhYmxlUXVldWVNZW1iZXJzKCksXG5cbiAgICAgICAgfSk7XG4gICAgfSxcblxuICAgIC8qKlxuICAgICAqIEluaXRpYWxpemUgRHJhZyBhbmQgRHJvcCBmdW5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